/*
 *  The tty.h header file defines some functions to manage the TTY (console)
 */

#ifndef _TTY_H
#define _TTY_H

#include <types.h>
#include <spinlock.h>

typedef struct {
  word_t *video_memory; // warning: it's word_t...
  int size;    // in number of word_t 
  int row,col;
  byte_t color;
  int max_row,max_col;
  word_t flags;
  byte_t echo;
  spinlock_t mutex;
} tty_t;

#define TTY_FLG_NONE    0
#define TTY_FLG_BIOS    1

#define TTY_ECHO_OFF    0
#define TTY_ECHO_ON     1

// Colors constants: foreground
#define TTY_COLOR_BLACK             0x00
#define TTY_COLOR_BLUE              0x01
#define TTY_COLOR_GREEN             0x02
#define TTY_COLOR_CYAN              0x03
#define TTY_COLOR_RED               0x04
#define TTY_COLOR_MAGENTA           0x05
#define TTY_COLOR_BROWN             0x06
#define TTY_COLOR_LIGHTGRAY         0x07
#define TTY_COLOR_DARKGRAY          0x08
#define TTY_COLOR_LIGHTBLUE         0x09
#define TTY_COLOR_LIGHTGREEN        0x0A
#define TTY_COLOR_LIGHTCYAN         0x0B
#define TTY_COLOR_LIGHTRED          0x0C
#define TTY_COLOR_LIGHTMAGENTA      0x0D
#define TTY_COLOR_YELLOW            0x0E
#define TTY_COLOR_WHITE             0x0F

// Colors constants: background
#define TTY_BG_COLOR_BLACK          0x00
#define TTY_BG_COLOR_BLUE           0x10
#define TTY_BG_COLOR_GREEN          0x20
#define TTY_BG_COLOR_CYAN           0x30
#define TTY_BG_COLOR_RED            0x40
#define TTY_BG_COLOR_MAGENTA        0x50
#define TTY_BG_COLOR_BROWN          0x60
#define TTY_BG_COLOR_LIGHTGRAY      0x70

// Colors constants: blinking text
#define TTY_COLOR_BLINK             0x80


// Colors constants: shortcuts
#define TTY_COLOR_NORMAL            (TTY_BG_COLOR_BLACK | TTY_COLOR_LIGHTGRAY)
#define TTY_COLOR_ERROR             (TTY_BG_COLOR_RED   | TTY_COLOR_LIGHTGRAY)


extern tty_t *system_tty;
extern tty_t *current_tty;

extern void tty_initialize(void);
extern void tty_clear(tty_t *tty);
extern int tty_write_char(tty_t *tty,int ch);
extern int tty_read_char(tty_t *tty,int *ch);

#endif /* _TTY_H */
